package com.xdb.sqlparser.dialect.oracle.ast;

import com.xdb.sqlparser.ast.SQLOrderBy;
import com.xdb.sqlparser.ast.statement.SQLSelectOrderByItem;
import com.xdb.sqlparser.dialect.oracle.ast.statement.OracleOrderByItem;
import com.xdb.sqlparser.dialect.oracle.visitor.OracleASTVisitor;
import com.xdb.sqlparser.visitor.SQLAstVisitor;

public class OracleOrderBy extends SQLOrderBy {

	private boolean sibings;

	public OracleOrderBy() {

	}

	public boolean isSibings() {
		return this.sibings;
	}

	public void setSibings(boolean sibings) {
		this.sibings = sibings;
	}

	protected void accept0(SQLAstVisitor visitor) {
		if (visitor instanceof OracleASTVisitor) {
			accept0((OracleASTVisitor) visitor);
		} else {
			super.accept0(visitor);
		}
	}

	protected void accept0(OracleASTVisitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.items);
		}

		visitor.endVisit(this);
	}

	public void output(StringBuffer buf) {
		buf.append("ORDER ");
		if (this.sibings) {
			buf.append("SIBLINGS ");
		}
		buf.append("BY ");

		int i = 0;
		for (int size = this.items.size(); i < size; ++i) {
			if (i != 0) {
				buf.append(", ");
			}
			((OracleOrderByItem) this.items.get(i)).output(buf);
		}
	}

	protected SQLSelectOrderByItem createItem() {
		return new OracleOrderByItem();
	}
}
